package com.tong.hao.ac.service.controller.test;

import cn.buddha.jec.util.TongBusinessUtils;
import cn.buddha.jec.util.TongStringUtils;
import com.tong.hao.ac.service.component.test.StrategyContext;
import com.tong.hao.common.exception.HaoExceptionEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author shihao
 * @description 策略模式测试类
 */
@Api(tags = {"策略模式控制器"})
@RestController
@Slf4j
@RequestMapping(value = "/htest")
public class StrategyController {

    @Autowired
    private StrategyContext strategyContext;

    @ApiOperation(value = "策略模式测试")
    @RequestMapping(value = "/strategy/{type}", method = RequestMethod.GET)
    public String testException(@PathVariable(value = "type") String type) {
        if (TongStringUtils.isEmpty(type)) {
            throw TongBusinessUtils.createBusinessException(HaoExceptionEnum.STRATEGY_EX.getCode(),
                    HaoExceptionEnum.STRATEGY_EX.getMessage());
        }
        return this.strategyContext.getStrategyImpl(type).who();
    }

}
